import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.List;

public class TankClient extends Frame{
	int x=50,y=50;
	 public static final int GAME_WIDTH = 800;
	  public static final int GAME_HEIGHT = 600;
	  Tank tank = new Tank(x, y);
	  Tank tank = new Tank(50, 50,this);
	  Missile m= new Missile(50,50,Tank.Direction.R);
	  public void update(Graphics g) {
	      Image offScreenImage = null;
	      if (offScreenImage == null) {
	          offScreenImage = this.createImage(800, 600);
	      }
	      Graphics gOffScreen = offScreenImage.getGraphics();
	      Color c = gOffScreen.getColor();
	      gOffScreen.setColor(Color.GREEN);
	      gOffScreen.fillRect(0, 0,800, 600);
	      gOffScreen.setColor(c);
	      print(gOffScreen);
	      g.drawImage(offScreenImage, 0, 0, null);
	  }
	 public void paint(Graphics g) {
		 tank.draw(g);
		 m.draw(g);
		tank.draw(g);
		 if(m!=null)m.draw(g);
	       }
	 public void launchFrame() {
	        this.setLocation(300, 50);
	        this.setSize(800,600);
	        this.setTitle("TankWar");
	        this.addWindowListener((WindowListener) new WindowAdapter() {
	            public void windowClosing(WindowEvent e) {
	                System.exit(0);
	            }
	        });
	        this.setResizable(false);
	        this.setBackground(Color.green);
	        this.addKeyListener(new KeyMonitor());
	        setVisible(true);

	        new Thread(new PaintThread()).start();
	    }
	 private class KeyMonitor extends KeyAdapter{
		 public void keyPressed(KeyEvent e) {
			 
	          tank.keyPressed(e);
		 }
		 @Override
	      public void keyReleased(KeyEvent e) {
	          tank.keyReleased(e);
	      }

	 }
	 private class PaintThread implements Runnable {//߳

	      @Override
	      public void run() {
	          while (true) {
	              repaint();
	              try {
	                  Thread.sleep(100);
	              } catch (InterruptedException e) {
	                  e.printStackTrace();
	              }
	          }
	      }
	  }

	 public static void main(String[] args) {
	  TankClient tc=new TankClient();
	  tc.launchFrame();
	 }
}